package com.smartrobot.smartrobot.service;


import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import com.smartrobot.smartrobot.Common.Common;
import com.smartrobot.smartrobot.logToSdCard.LogToSd;
import com.smartrobot.smartrobot.websocket.socketUtil;


/**
 * Created by yeluojun on 2015/1/7.
 */
public class webscoketService extends Service {


    public static final String TAG = "webSocketService";
    private MyBinder mBinder = new MyBinder();


    @Override
    public void onCreate(){
        if(Common._websocketHandler2==null){
            socketUtil.initSocket_2(this);
        }
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        try{
            Log.e("开启服务========== ","onStartCommand");
            Thread.sleep(1000);
            if(Common._websocketHandler2==null){
                socketUtil.initSocket_2(this);
                Log.e("发送消息 ","onStartCommand");
            }

        }catch (Exception E){
            LogToSd.log_init();
            LogToSd.error("创建websocket链接失败：" + E.toString());
            Log.e("===========创建websocket链接失败2===========", E.toString());
        }

        Log.d(TAG, "onStartCommand() executed");

        return super.onStartCommand(intent, flags, startId);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy() executed");
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }


    //绑定的内容
    public class MyBinder extends Binder {

        public void heartBeat() {
        }
    }

    public  static void  init(Context arg_context){
//        context = arg_context;
//        websocketHandle_2.init(arg_context);
    }

}
